<?php


namespace app\admin\controller;


use app\admin\model\RegionModel;
use app\BaseController;
use app\common\Constants\ErrorCode;
use think\response\Json;

class Region extends BaseController
{
    /**
     * @author ran
     * @date 2021-11-03 15:48
     * mailbox 466180170@qq.com
     */
    public function initialize()
    {
        /*
        $action = [
            'permission' => ['exportcsv','import'],
            'allow' => [
                'synckingdeestock'
            ]
        ];
        event('CheckAuth', $action);
        $request = $this->request;
        $a       = strtolower($request->action());
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }*/
    }
    /**
     * 创建店铺大区资源
     * @author ran
     * @date 2021-09-16 14:12
     * mailbox 466180170@qq.com
     */
    public function createShopAdminRegionResource():Json
    {
        $request = $this->request->param();
        $model = new RegionModel();
        $res          = $model->createShopAdminRegionResource($request);
        if (!$res) {
            return  $this->failed(ErrorCode::SYSTEM_INVALID,$model->getError());
        }
        return  $this->success([],'创建成功');
    }
    /**
     * 更新
     * @author ran
     * @date 2021-09-25 15:47
     * mailbox 466180170@qq.com
     */
    public function updateShopAdminRegionResource(){
        $request = $this->request->param();
        $model = new RegionModel();
        $res          = $model->updateShopAdminRegionResource($request);
        if (!$res) {
            return  $this->failed(ErrorCode::SYSTEM_INVALID,$model->getError());
        }
        return  $this->success([],'更新成功');
    }
    /**
     * 获取店铺大区资源
     * @return Json
     * @author ran
     * @date 2021-09-22 17:09
     * mailbox 466180170@qq.com
     */
    public function readShopAdminRegionInfo():Json
    {
        $id = $this->request->param('id');
        if (empty($id)) return $this->failed(ErrorCode::SYSTEM_INVALID);
        $model = new RegionModel();
        $res          = $model->getShopAdminRegionInfoResource((int)$id);
        return $this->success($res,'获取成功');
    }
    /**
     * @return Json
     * @author ran
     * @date 2021-09-23 13:54
     * mailbox 466180170@qq.com
     */
    public function readAdminRegionList():Json
    {
        $request = $this->request->param();
        $model = new RegionModel();
        if (empty($request['page']) || empty($request['limit'])) return $this->failed(ErrorCode::SYSTEM_INVALID);
        $res          = $model->getShopAdminRegionListResource((int)$request['page'],(int)$request['limit']);
        return $this->success($res,'获取资源成功',$res['dataCount']);
    }
}